package org.bigdata.framework.core.protocol;

import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.bigdata.framework.core.model.DiyCss;
import org.bigdata.framework.core.model.DiyFile;
import org.bigdata.framework.core.model.DiyImages;
import org.bigdata.framework.core.model.DiyJavascript;
import org.bigdata.framework.core.model.DiyModule;
import org.bigdata.framework.core.model.DiyPage;
import org.bigdata.framework.core.model.DiyPageModule;
import org.bigdata.framework.core.model.DiyPageSubmit;
import org.bigdata.framework.core.model.DiyTemplate;
import org.bigdata.framework.core.service.IDiyCssService;
import org.bigdata.framework.core.service.IDiyFileService;
import org.bigdata.framework.core.service.IDiyImagesService;
import org.bigdata.framework.core.service.IDiyJavascriptService;
import org.bigdata.framework.core.service.IDiyModuleService;
import org.bigdata.framework.core.service.IDiyPageModuleService;
import org.bigdata.framework.core.service.IDiyPageService;
import org.bigdata.framework.core.service.IDiyPageSubmitService;
import org.bigdata.framework.core.service.IDiyTemplateService;
import org.bigdata.framework.core.utils.MybatisPlusTools;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.plugins.Page;

/**
 * diy模块 2017-04-21
 * 
 * @author anhuifeng
 * 
 */
public class DiyService implements IDiyService {

	private static final Logger LOG = Logger.getLogger(DiyService.class);
	
	@Autowired
	private IDiyPageService diyPageService;
	@Autowired
	private IDiyCssService diyCssService;
	@Autowired
	private IDiyFileService diyFileService;
	@Autowired
	private IDiyImagesService diyImagesService;
	@Autowired
	private IDiyJavascriptService diyJavascriptService;
	@Autowired
	private IDiyModuleService diyModuleService;
	@Autowired
	private IDiyPageModuleService diyPageModuleService;
	@Autowired
	private IDiyPageSubmitService diyPageSubmitService;
	@Autowired
	private IDiyTemplateService diyTemplateService;
	
	@Override
	public DiyPage saveDiyPage(DiyPage diyPage) {
		boolean r = diyPageService.insert(diyPage);
		if (r) {
			return diyPage;
		}
		return null;
	}

	@Override
	public DiyPage editDiyPage(DiyPage diyPage) {
		boolean r = diyPageService.updateAllColumnById(diyPage);
		if (r) {
			return diyPage;
		}
		return null;
	}

	@Override
	public void deleteDiyPage(DiyPage diyPage) {
		boolean r = diyPageService.deleteById(diyPage.getId());
		if (r) {
			System.out.println("diyPage 删除成功>>>" + diyPage.getId());
		}
	}

	@Override
	public DiyPage findDiyPage(Integer id) {
		return diyPageService.selectById(id);
	}

	@Override
	public List<DiyPage> getDiyPage() {
		return diyPageService.selectList(null);
	}

	@Override
	public List<DiyPage> getDiyPage(HashMap<String, Object> queryParams,
			int pageNumber, int pageSize) {
		if(queryParams!=null && !"".equals(queryParams)){
			queryParams.put("^,sort", "asc");
		}
		return diyPageService.selectPage(new Page<DiyPage>(pageNumber, pageSize),
				new MybatisPlusTools<DiyPage>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getDiyPageCount(HashMap<String, Object> queryParams) {
		return diyPageService.selectCount(new MybatisPlusTools<DiyPage>()
				.getEwByCount(queryParams));
	}

	@Override
	public DiyCss saveDiyCss(DiyCss diyCss) {
		boolean r = diyCssService.insert(diyCss);
		if (r) {
			return diyCss;
		}
		return null;
	}

	@Override
	public DiyCss editDiyCss(DiyCss diyCss) {
		boolean r = diyCssService.updateAllColumnById(diyCss);
		if (r) {
			return diyCss;
		}
		return null;
	}

	@Override
	public void deleteDiyCss(DiyCss diyCss) {
		boolean r = diyCssService.deleteById(diyCss.getId());
		if (r) {
			System.out.println("diyCss 删除成功>>>" + diyCss.getId());
		}
		
	}

	@Override
	public DiyCss findDiyCss(String id) {
		return diyCssService.selectById(id);
	}

	@Override
	public List<DiyCss> getDiyCss(HashMap<String, Object> queryParams,
			int pageNumber, int pageSize) {
		if(queryParams!=null && !"".equals(queryParams)){
			queryParams.put("^,sort", "asc");
		}
		return diyCssService.selectPage(new Page<DiyCss>(pageNumber, pageSize),
				new MybatisPlusTools<DiyCss>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getDiyCssCount(HashMap<String, Object> queryParams) {
		return diyCssService.selectCount(new MybatisPlusTools<DiyCss>()
				.getEwByCount(queryParams));
	}

	@Override
	public DiyJavascript saveDiyJavascript(DiyJavascript diyJavascript) {
		boolean r = diyJavascriptService.insert(diyJavascript);
		if (r) {
			return diyJavascript;
		}
		return null;
	}

	@Override
	public DiyJavascript editDiyJavascript(DiyJavascript diyJavascript) {
		boolean r = diyJavascriptService.updateAllColumnById(diyJavascript);
		if (r) {
			return diyJavascript;
		}
		return null;
	}

	@Override
	public void deleteDiyJavascript(DiyJavascript diyJavascript) {
		boolean r = diyJavascriptService.deleteById(diyJavascript.getId());
		if (r) {
			System.out.println("diyJavascript 删除成功>>>" + diyJavascript.getId());
		}
	}

	@Override
	public DiyJavascript findDiyJavascript(String id) {
		return diyJavascriptService.selectById(id);
	}

	@Override
	public List<DiyJavascript> getDiyJavascript(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		if(queryParams!=null && !"".equals(queryParams)){
			queryParams.put("^,sort", "asc");
		}
		return diyJavascriptService.selectPage(new Page<DiyJavascript>(pageNumber, pageSize),
				new MybatisPlusTools<DiyJavascript>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getDiyJavascriptCount(HashMap<String, Object> queryParams) {
		return diyJavascriptService.selectCount(new MybatisPlusTools<DiyJavascript>()
				.getEwByCount(queryParams));
	}

	@Override
	public DiyImages saveDiyImages(DiyImages diyImages) {
		boolean r = diyImagesService.insert(diyImages);
		if (r) {
			return diyImages;
		}
		return null;
	}

	@Override
	public DiyImages editDiyImages(DiyImages diyImages) {
		boolean r = diyImagesService.updateAllColumnById(diyImages);
		if (r) {
			return diyImages;
		}
		return null;
	}

	@Override
	public void deleteDiyImages(DiyImages diyImages) {
		boolean r = diyImagesService.deleteById(diyImages.getId());
		if (r) {
			System.out.println("diyImages 删除成功>>>" + diyImages.getId());
		}
	}

	@Override
	public DiyImages findDiyImages(String id) {
		return diyImagesService.selectById(id);
	}

	@Override
	public List<DiyImages> getDiyImages(HashMap<String, Object> queryParams,
			int pageNumber, int pageSize) {
		if(queryParams!=null && !"".equals(queryParams)){
			queryParams.put("^,sort", "asc");
		}
		return diyImagesService.selectPage(new Page<DiyImages>(pageNumber, pageSize),
				new MybatisPlusTools<DiyImages>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getDiyImagesCount(HashMap<String, Object> queryParams) {
		return diyImagesService.selectCount(new MybatisPlusTools<DiyImages>()
				.getEwByCount(queryParams));
	}

	@Override
	public DiyFile saveDiyFile(DiyFile diyFile) {
		boolean r = diyFileService.insert(diyFile);
		if (r) {
			return diyFile;
		}
		return null;
	}

	@Override
	public DiyFile editDiyFile(DiyFile diyFile) {
		boolean r = diyFileService.updateAllColumnById(diyFile);
		if (r) {
			return diyFile;
		}
		return null;
	}

	@Override
	public void deleteDiyFile(DiyFile diyFile) {
		boolean r = diyFileService.deleteById(diyFile.getId());
		if (r) {
			System.out.println("diyFile 删除成功>>>" + diyFile.getId());
		}
	}

	@Override
	public DiyFile findDiyFile(String id) {
		return diyFileService.selectById(id);
	}

	@Override
	public List<DiyFile> getDiyFile(HashMap<String, Object> queryParams,
			int pageNumber, int pageSize) {
		if(queryParams!=null && !"".equals(queryParams)){
			queryParams.put("^,sort", "asc");
		}
		return diyFileService.selectPage(new Page<DiyFile>(pageNumber, pageSize),
				new MybatisPlusTools<DiyFile>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getDiyFileCount(HashMap<String, Object> queryParams) {
		return diyFileService.selectCount(new MybatisPlusTools<DiyFile>()
				.getEwByCount(queryParams));
	}

	@Override
	public DiyTemplate saveDiyTemplate(DiyTemplate diyTemplate) {
		boolean r = diyTemplateService.insert(diyTemplate);
		if (r) {
			return diyTemplate;
		}
		return null;
	}

	@Override
	public DiyTemplate editDiyTemplate(DiyTemplate diyTemplate) {
		boolean r = diyTemplateService.updateAllColumnById(diyTemplate);
		if (r) {
			return diyTemplate;
		}
		return null;
	}

	@Override
	public void deleteDiyTemplate(DiyTemplate diyTemplate) {
		boolean r = diyTemplateService.deleteById(diyTemplate.getId());
		if (r) {
			System.out.println("diyTemplate 删除成功>>>" + diyTemplate.getId());
		}
	}

	@Override
	public DiyTemplate findDiyTemplate(String id) {
		return diyTemplateService.selectById(id);
	}

	@Override
	public List<DiyTemplate> getDiyTemplate(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		if(queryParams!=null && !"".equals(queryParams)){
			queryParams.put("^,sort", "asc");
		}
		return diyTemplateService.selectPage(new Page<DiyTemplate>(pageNumber, pageSize),
				new MybatisPlusTools<DiyTemplate>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getDiyTemplateCount(HashMap<String, Object> queryParams) {
		return diyTemplateService.selectCount(new MybatisPlusTools<DiyTemplate>()
				.getEwByCount(queryParams));
	}

	@Override
	public DiyModule saveDiyModule(DiyModule diyModule) {
		boolean r = diyModuleService.insert(diyModule);
		if (r) {
			return diyModule;
		}
		return null;
	}

	@Override
	public DiyModule editDiyModule(DiyModule diyModule) {
		boolean r = diyModuleService.updateAllColumnById(diyModule);
		if (r) {
			return diyModule;
		}
		return null;
	}

	@Override
	public void deleteDiyModule(DiyModule diyModule) {
		boolean r = diyModuleService.deleteById(diyModule.getId());
		if (r) {
			System.out.println("diyModule 删除成功>>>" + diyModule.getId());
		}
	}

	@Override
	public DiyModule findDiyModule(String id) {
		return diyModuleService.selectById(id);
	}

	@Override
	public List<DiyModule> getDiyModule(HashMap<String, Object> queryParams,
			int pageNumber, int pageSize) {
		if(queryParams!=null && !"".equals(queryParams)){
			queryParams.put("^,sort", "asc");
		}
		return diyModuleService.selectPage(new Page<DiyModule>(pageNumber, pageSize),
				new MybatisPlusTools<DiyModule>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getDiyModuleCount(HashMap<String, Object> queryParams) {
		return diyModuleService.selectCount(new MybatisPlusTools<DiyModule>()
				.getEwByCount(queryParams));
	}

	@Override
	public DiyPageModule saveDiyPageModule(DiyPageModule diyPageModule) {
		boolean r = diyPageModuleService.insert(diyPageModule);
		if (r) {
			return diyPageModule;
		}
		return null;
	}

	@Override
	public DiyPageModule editDiyPageModule(DiyPageModule diyPageModule) {
		boolean r = diyPageModuleService.updateAllColumnById(diyPageModule);
		if (r) {
			return diyPageModule;
		}
		return null;
	}

	@Override
	public void deleteDiyPageModule(DiyPageModule diyPageModule) {
		boolean r = diyPageModuleService.deleteById(diyPageModule.getId());
		if (r) {
			System.out.println("diyPageModule 删除成功>>>" + diyPageModule.getId());
		}
	}

	@Override
	public DiyPageModule findDiyPageModule(String id) {
		return diyPageModuleService.selectById(id);
	}

	@Override
	public List<DiyPageModule> getDiyPageModule(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		if(queryParams!=null && !"".equals(queryParams)){
			queryParams.put("^,sort", "asc");
		}
		return diyPageModuleService.selectPage(new Page<DiyPageModule>(pageNumber, pageSize),
				new MybatisPlusTools<DiyPageModule>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getDiyPageModuleCount(HashMap<String, Object> queryParams) {
		return diyPageModuleService.selectCount(new MybatisPlusTools<DiyPageModule>()
				.getEwByCount(queryParams));
	}

	@Override
	public DiyPageSubmit saveDiyPageSubmit(DiyPageSubmit diyPageSubmit) {
		boolean r = diyPageSubmitService.insert(diyPageSubmit);
		if (r) {
			return diyPageSubmit;
		}
		return null;
	}

	@Override
	public DiyPageSubmit editDiyPageSubmit(DiyPageSubmit diyPageSubmit) {
		boolean r = diyPageSubmitService.updateAllColumnById(diyPageSubmit);
		if (r) {
			return diyPageSubmit;
		}
		return null;
	}

	@Override
	public void deleteDiyPageSubmit(DiyPageSubmit diyPageSubmit) {
		boolean r = diyPageSubmitService.deleteById(diyPageSubmit.getId());
		if (r) {
			System.out.println("diyPageSubmit 删除成功>>>" + diyPageSubmit.getId());
		}
	}

	@Override
	public DiyPageSubmit findDiyPageSubmit(String id) {
		return diyPageSubmitService.selectById(id);
	}

	@Override
	public List<DiyPageSubmit> getDiyPageSubmit(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		return diyPageSubmitService.selectPage(new Page<DiyPageSubmit>(pageNumber, pageSize),
				new MybatisPlusTools<DiyPageSubmit>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getDiyPageSubmitCount(HashMap<String, Object> queryParams) {
		return diyPageSubmitService.selectCount(new MybatisPlusTools<DiyPageSubmit>()
				.getEwByCount(queryParams));
	}
	
}
